<template>
  <div class="searchDetailsBox">
    <search v-show="isShow" v-model:isShow="isShow" v-model:valueDta="valueDta"/>
    <van-sticky>
      <div v-show="!isShow">
        <van-search v-model="value"
                    placeholder="请输入搜索关键词"
                    clearable
                    @focus="isShowHandel"
        />
      </div>
    </van-sticky>


    <div class="box">
      <div class="content1" v-for="(list,index) in listData?.directlyList" :key="list.id" @click="gotoDetails(list.id)">
        <div class="contentImg">
          <img :src="list.listPicUrl" alt="" class="img">
        </div>
        <div class="title">
            <span class="name">
                <span v-for="(img,index) in list.preLogo" :key="index">
                  <img class="listImg" alt="" :src="img.logoUrl">
                </span>
              {{ list.name }}
            </span>
        </div>
        <div class="price">
          <span class="yuan">￥</span>
          <span class="newPrice">{{ list.retailPrice }}</span>
          <span class="lodYuan"><del>{{ list.sortOriginPrice }}</del></span>
        </div>
        <div class="footer">
          <div class="left">
            新人特价
          </div>
          <div class="right" v-if="list.finalPriceInfoVO.banner?.content">
            {{ list.finalPriceInfoVO.banner?.content }}
          </div>
        </div>
      </div>
    </div>

  </div>


</template>

<script lang="ts">
import { defineComponent } from "vue";

export default defineComponent({
  name: "SearchDetails",
});
</script>

<script lang="ts" setup>
import { onMounted, ref, watch } from "vue";
import { useRoute, useRouter } from 'vue-router'
import { getSearchDetailsApi } from "@/api/search";
import type { searchList } from "@/api/modules/search";
import useSearchStore from '@/stores/modules/search'
import search from "@/view/search/index.vue";
import type { searchData } from '@/api/modules/search'

const searchStore = useSearchStore()

const isShow = ref(false)
const route = useRoute()
const router = useRouter()
const listData = ref<searchList>()
const emits = defineEmits(['isShow', 'valueDta'])
const isShowHandel = () => {
  searchStore.getErrorIsShow(false)
  isShow.value = !isShow.value
  emits('isShow', isShow)
}
onMounted(async () => {
  listData.value = await getSearchDetailsApi(route.query.keyword as string)
})
watch(route, async (value) => {
  listData.value = await getSearchDetailsApi(route.query.keyword as string)
})
const value = ref('');
const valueDta = ref('')

// 点击去详情页
const gotoDetails = (id: string) => {
  router.push({
    path: '/item/detail',
    query: {id}
  })
}
</script>

<style lang="less" scoped>
.searchDetailsBox {
  height: 100%;
}

.box {
  display: flex;
  justify-content: space-between;
  padding: 0px 10px 15px 10px;
  flex-wrap: wrap;
}

.content1 {
  display: flex;
  flex-direction: column;
  height: 275px;
  justify-content: space-between;
  margin-top: 20px;

  .contentImg {
    .img {
      width: 172.5px;
      height: 172.5px;
    }
  }

  .title {
    display: flex;
    font-size: 16px;
    width: 172.5px;
    overflow: hidden;
    text-overflow: ellipsis;
    -webkit-box-orient: vertical;

    .listImg {
      width: 35px;
      height: 18px;
    }

    .name {
      font-size: 14px;
    }
  }

  .price {
    display: flex;
    align-items: center;

    .yuan {
      font-size: 10px;
      color: rgb(250, 30, 50);
      font-weight: 900;
    }

    .newPrice {
      color: rgb(250, 30, 50);
      font-size: 16px;
      font-weight: 900;
    }

    .lodYuan {
      font-size: 10px;
    }
  }

  .footer {
    display: flex;
    align-items: center;
    width: 172.5px;

    .left {
      font-size: 12px;
      color: #fff;
      font-weight: 900;
      width: 60px;
      background-color: #fa1e32;
      height: 20px;
      text-align: center;
      line-height: 20px;
      border-radius: 20px;
    }

    .right {
      font-size: 10px;
      height: 20px;
      color: rgb(250, 30, 50);
      background-color: #ffe9eb;
      flex: 1;
      text-align: center;
      line-height: 22px;
      border-radius: -20px 0 0 -20px;
    }
  }
}
</style>
